Repository navigation
fix(isc): autoload CaptureRef; named error for unpaired refs in from (WO20 fuzz #864) - #866
Merged
Merged
Conversation
WO20 fuzz fix (interscript-ruby#864, campaign: interscript/maps#284): `ref(N)` in an ISC map crashed with NameError: uninitialized constant Node::Item::CaptureRef - the class exists in item/capture.rb but had no autoload entry, so the constant only resolved when an earlier dependency parse happened to touch CaptureGroup first (27 corpus maps with to-position refs escaped by that accident). - node/item.rb: give CaptureRef its own autoload entry, making the constant order-independent. - isc/node_adapter.rb: a ref whose capture group the from expression never opens is rejected at parse with a named MapLogicError - the WO18 G8 fn-literal-in-from convention (a named error, never an accidental exception; pre-fix this surface was the NameError). The pairing gate is count-based because Onigmo accepts any existing group number from any position: paired refs (the geminate idiom `from capture(any_character) + ref(1)`, pinned by node_adapter_spec) and to-position refs stay legal. Whether unpaired refs should be a run-time error like ts/py/rs is the owner-held cross-runtime question from the fuzz triage. Corpus proof: all 428 maps + 7 libs parse with identical outcomes pre/post change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the ruby crash class found by the WO20 differential fuzz campaign (triage: interscript/maps#284,
scripts/fuzz/TRIAGE.md) - interscript-ruby#864, 14 cases.Root cause.
Node::Item::CaptureRefexists (defined initem/capture.rb, next toCaptureGroup) but had no autoload entry innode/item.rb. Any map referencingref(N)crashed withNameError: uninitialized constant Interscript::Node::Item::CaptureRefunless some earlier dependency parse had already referencedCaptureGroup- which loads the file and defines both classes as a side effect. The 27 corpus maps carryingto-position refs parse today only by that accident; the fuzz repros (isolated maps) crashed.Fix.
node/item.rb: the missingautoload :CaptureRef, "interscript/node/item/capture"- the constant is now order-independent.isc/node_adapter.rb: a capture ref whose capture group the from expression never opens is rejected at parse with a namedMapLogicError- mirroring the WO18 G8 fn-literal-in-from convention (a named error, never an accidental exception; pre-fix this exact surface was theNameError, post-autoload-only it would be an accidentalRegexpError: invalid backrefat compile).Scoping matters. A blanket from-position rejection would break a construct main explicitly pins:
spec/interscript/isc/node_adapter_spec.rbrunsfrom capture(any_character) + ref(1)(the geminate idiom) end-to-end. The gate is therefore pairing-based - Onigmo accepts any existing group number from any position (forward and nested refs included), so aref(N)is valid iff the from expression opens >= N capture groups (CaptureGroupis the only capturing wrapper the interpreter emits).to-position refs (27 corpus maps) are untouched. Whether unpaired refs should instead be a run-time error like ts/py/rs is the owner-held cross-runtime question from the fuzz triage - this PR only removes the accidental exceptions.Tests (
spec/isc/fail_loud_spec.rb, WO20 section)Interscript::MapLogicError: ref(1) in from position has no matching capture group(wasNameError).some(ref(1))-> same named rejection.чч->ч).CaptureRefautoload entry pinned in a fresh process (order-independent; the in-process form was order-fragile against suite pollution).MapLogicError, neverNameError.to-position ref parses and runs as a backreference (kk->WkWk), in-process and in a fresh process.Gates
bundle exec rake spec: 438 examples, 0 failures, 11 pending (SKIP_JS=1 SKIP_PYTHON=1, the CI configuration; the two cross-compiler execution legs are owned by the push matrix).standardrb: clean on all touched files (the one remainingcodemod.rboffense pre-exists onorigin/main).4c47eb5worktree).--hand-rev 7a84260).hk-yue-Han-Latn-govt, remove trailing space from map characters #44); smoke corpus untouched.Fixes #864